from lowlevel import *
from midlevel import *
from ant import Ant
import sys,os,time,random
from worker import *

def __main__(mod,args=sys.argv):
    if(".py" in args[0]):##Determine whether call came from command line
        if(len(args)<2):
            var=raw_input("Specify target folder")
        else:
            var=args[1]
        tasklist=list()
        for item in airborne(os.path.abspath(var)):
            tasklist.append(item)
    else:
        tasklist=args[0]##Call from other script
    if(mod=="artist"):
        company=[artisttor() for i in range(2)]
    elif(mod=="genre"):
        company=[genretor() for i in range(2)]
    elif(mod=="album"):
        company=[albumtor() for i in range(2)]
    else:
        raise LookupError
    company[0].fill_local()
    for member in company:
        member.start()
    initial_length_of_tasklist=len(tasklist)
    for i in range(initial_length_of_tasklist):
        random_position=random.randint(0,len(tasklist)-1)
        temp=tasklist.pop(random_position)
        if(".mp3" in temp and "mpg" not in temp):
            type(company[0]).pile.put(temp)
    enter_wait(company[0])
    sort_file(filename(company[0])+'.txt')
    artisttor.local={}
    genretor.local={}
tasklist=list()
var=raw_input("What do you want to do?artist/album/genre\n")

if "artist" in var:
    __main__("artist",sys.argv)
if "genre" in var:
    __main__("genre",sys.argv)
if "album" in var:
    __main__("album",sys.argv)



    
        
        
